<script setup>
import { reactive, ref, watch, nextTick, onMounted } from 'vue'
import { User, Lock } from '@element-plus/icons-vue'
import { login } from '../api/login.js'
import { ElMessage } from 'element-plus'
import { CONFIG } from '../config/index.js'
import { useRouter } from 'vue-router'
import { loadSlim } from "tsparticles-slim";
import { tsParticles } from "tsparticles-engine";
import { ElNotification } from 'element-plus'
import { h } from 'vue'
const loginInfo = reactive({ username: '', password: '' })
const rules = reactive({
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
})
const loginButtonDisabled = ref(true)
const loginRef = ref()
const owlRef = ref()
const router = useRouter()
watch([() => loginInfo.username, () => loginInfo.password], ([username, password]) => {
  loginButtonDisabled.value = !(username && password);
});
const submitForm = () => {
  loginRef.value.validate((valid) => {
    if (!valid) return
    login(loginInfo.username, loginInfo.password).then((response) => {
      if (response.data.status === 200) {
        localStorage.setItem(CONFIG.TOKEN_NAME, response.data.data.token)
        ElMessage.success(response.data.message)
        router.replace('/')
      }
    })
      ElNotification({
    title: '你好呀，朋友',
    message: h('p', null, [
    h('span', { style: 'color: #6366f1' }, '欢迎来到'),
    h('span', { style: 'color: #ec4899' }, '唐唐的Kubernetes管理平台'),
  ]),
    type: 'success',
    offset: 100,
  })
  })
}
onMounted( async () => {
  await loadSlim(tsParticles);
  await tsParticles.load("particles-js", {
    background: { color: { value: "transparent" } },
    fullScreen: { enable: false },
    particles: {
      number: { value: 60 },
      size: { 
        value: { min: 1, max: 3 },
        animation: {
          enable: true,
          speed: 2,
          minimumValue: 0.1
        }
      },
      color: { 
        value: ["#6366f1", "#8b5cf6", "#ec4899", "#06b6d4"]
      },
      opacity: { 
        value: { min: 0.3, max: 0.8 },
        animation: {
          enable: true,
          speed: 1,
          minimumValue: 0.1
        }
      },
      move: { 
        enable: true, 
        speed: { min: 0.5, max: 2 },
        direction: "none",
        outModes: {
          default: "out"
        }
      },
      links: {
        enable: true,
        distance: 120,
        color: "#6366f1",
        opacity: 0.3,
        width: 1
      }
    },
    interactivity: {
      events: {
        onHover: { enable: true, mode: "attract" },
        onClick: { enable: true, mode: "push" }
      },
      modes: {
        attract: { distance: 200, duration: 0.4 },
        push: { quantity: 4 }
      }
    }
  });
  
  nextTick(() => {
    const passwordInput = document.querySelector('#password')
    if (passwordInput) {
      passwordInput.addEventListener('focus', () => {
        owlRef.value?.classList.add('password')
      })
      passwordInput.addEventListener('blur', () => {
        owlRef.value?.classList.remove('password')
      })
    }
    document.querySelectorAll('.login-btn').forEach(btn => {
      btn.addEventListener('click', function (e) {
        const ripple = document.createElement('span')
        ripple.className = 'ripple'
        const rect = this.getBoundingClientRect()
        const size = Math.max(rect.width, rect.height)
        ripple.style.width = size + 'px'
        ripple.style.height = size + 'px'
        ripple.style.left = (e.clientX - rect.left - size / 2) + 'px'
        ripple.style.top = (e.clientY - rect.top - size / 2) + 'px'
        this.appendChild(ripple)
        setTimeout(() => ripple.remove(), 1000)
      })
    })
  })
})
</script>
<template>
  <div class="login-container">
    <div id="particles-js"></div>
    
    <!-- 装饰性元素 -->
    <div class="decoration-elements">
      <div class="floating-circle circle-1"></div>
      <div class="floating-circle circle-2"></div>
      <div class="floating-circle circle-3"></div>
      <div class="floating-triangle triangle-1"></div>
      <div class="floating-triangle triangle-2"></div>
    </div>
    <div class="login-card">
      <!-- 头部区域 -->
      <div class="card-header">
        <div class="logo-section">
          <!-- Logo图标 -->
          <div class="logo-icon">
            <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
              <path d="M12 2L2 7L12 12L22 7L12 2Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
              <path d="M2 17L12 22L22 17" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
              <path d="M2 12L12 17L22 12" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
            </svg>
          </div>
          
          <!-- 标题区域 -->
          <div class="title-section">
            <h1 class="main-title">唐唐 KubeManager</h1>
            <p class="subtitle">现代化容器编排管理平台</p>
          </div>
        </div>
      </div>
      <!-- 猫头鹰 -->
      <div class="owl-container">
        <div id="owl-login" ref="owlRef">
          <div class="eyes"></div>
          <div class="arm-up-right"></div>
          <div class="arm-up-left"></div>
          <div class="arm-down-left"></div>
          <div class="arm-down-right"></div>
        </div>
      </div>
      <!-- 表单区域 -->
      <div class="form-container">
        <el-form 
          ref="loginRef" 
          :model="loginInfo" 
          :rules="rules" 
          status-icon 
          class="login-form"
        >
          <el-form-item prop="username" class="form-item">
            <el-input 
              placeholder="请输入用户名" 
              clearable 
              :prefix-icon="User" 
              v-model="loginInfo.username" 
              class="styled-input"
              @keyup.enter="submitForm"
              size="large"
            />
          </el-form-item>
          <el-form-item prop="password" class="form-item">
            <el-input 
              placeholder="请输入密码" 
              show-password 
              :prefix-icon="Lock" 
              v-model="loginInfo.password" 
              type="password" 
              autocomplete="off" 
              id="password" 
              class="styled-input" 
              @keyup.enter="submitForm"
              size="large"
            />
          </el-form-item>
          <el-form-item class="form-item form-item-button">
            <el-button 
              class="login-btn" 
              :disabled="loginButtonDisabled" 
              type="primary" 
              @click="submitForm"
              size="large"
            >
              <span class="btn-content">
                <svg class="btn-icon" viewBox="0 0 24 24" fill="none">
                  <path d="M15 3H19C20.1046 3 21 3.89543 21 5V19C21 20.1046 20.1046 21 19 21H15" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                  <path d="M10 17L15 12L10 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                  <path d="M15 12H3" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
                登录系统
              </span>
            </el-button>
          </el-form-item>
        </el-form>
        <div class="login-footer">
          <div class="feature-tags">
            <span class="tag">容器编排</span>
            <span class="tag">集群管理</span>
            <span class="tag">服务监控</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped>
/* 全局重置 */
* {
  box-sizing: border-box;
}
/* 全局容器样式 */
.login-container {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, 
    #667eea 0%, 
    #764ba2 25%, 
    #f093fb 50%, 
    #f5576c 75%, 
    #4facfe 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
/* 粒子背景 */
#particles-js {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
}
/* 装饰性浮动元素 */
.decoration-elements {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}
.floating-circle {
  position: absolute;
  border-radius: 50%;
  background: linear-gradient(45deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  backdrop-filter: blur(10px);
  animation: float 6s ease-in-out infinite;
}
.circle-1 {
  width: 120px;
  height: 120px;
  top: 10%;
  left: 15%;
  animation-delay: 0s;
}
.circle-2 {
  width: 80px;
  height: 80px;
  top: 70%;
  right: 20%;
  animation-delay: 2s;
}
.circle-3 {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 10%;
  animation-delay: 4s;
}
.floating-triangle {
  position: absolute;
  width: 0;
  height: 0;
  animation: rotate 8s linear infinite;
}
.triangle-1 {
  border-left: 30px solid transparent;
  border-right: 30px solid transparent;
  border-bottom: 52px solid rgba(236, 72, 153, 0.1);
  top: 20%;
  right: 15%;
  animation-delay: 1s;
}
.triangle-2 {
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-bottom: 35px solid rgba(6, 182, 212, 0.1);
  bottom: 30%;
  right: 30%;
  animation-delay: 3s;
}
@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(10deg); }
}
@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
/* 登录卡片 */
.login-card {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 450px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  overflow: hidden;
  animation: cardEntry 0.8s ease-out;
}
@keyframes cardEntry {
  from {
    opacity: 0;
    transform: translateY(50px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
/* 卡片头部 */
.card-header {
  padding: 40px 40px 20px;
  text-align: center;
}
.logo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.logo-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
  animation: logoGlow 3s ease-in-out infinite;
}
.logo-icon svg {
  width: 32px;
  height: 32px;
}
@keyframes logoGlow {
  0%, 100% { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3); }
  50% { box-shadow: 0 8px 32px rgba(99, 102, 241, 0.6); }
}
.title-section {
  text-align: center;
  width: 100%;
}
.main-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px 0;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.3;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  background: linear-gradient(135deg, #6366f1, #ec4899, #ffffff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0;
  font-weight: 400;
  line-height: 1.4;
}
/* 猫头鹰容器 */
.owl-container {
  display: flex;
  justify-content: center;
  padding: 20px;
}
#owl-login {
  width: 116px;
  height: 92px;
  background-image: url('https://cdn.jsdelivr.net/gh/iamkun/vue-login-owl@master/src/assets/face.png');
  position: relative;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2));
  transition: all 0.3s ease;
}
#owl-login:hover {
  transform: scale(1.05);
}
.eyes, .arm-up-right, .arm-up-left, .arm-down-left, .arm-down-right {
  position: absolute;
  background-repeat: no-repeat;
}
.arm-up-right {
  width: 51px; 
  height: 41px; 
  background-image: url('https://cdn.jsdelivr.net/gh/iamkun/vue-login-owl@master/src/assets/arm-up-right.png');
  bottom: 11px; 
  right: 5px; 
  transform: translateX(57px) scale(0.8); 
  transform-origin: 0 40px; 
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.arm-up-left {
  width: 52px; 
  height: 41px; 
  background-image: url('https://cdn.jsdelivr.net/gh/iamkun/vue-login-owl@master/src/assets/arm-up-left.png');
  bottom: 11px; 
  left: -3px; 
  transform: translateX(-34px) scale(0.8); 
  transform-origin: 0 40px; 
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.arm-down-left {
  width: 43px; 
  height: 25px; 
  background-image: url('https://cdn.jsdelivr.net/gh/iamkun/vue-login-owl@master/src/assets/arm-down-left.png');
  bottom: 2px; 
  left: -34px; 
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.arm-down-right {
  width: 43px; 
  height: 26px; 
  background-image: url('https://cdn.jsdelivr.net/gh/iamkun/vue-login-owl@master/src/assets/arm-down-right.png');
  bottom: 1px; 
  right: -40px; 
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#owl-login.password .arm-up-left, 
#owl-login.password .arm-up-right {
  transform: scale(1);
  opacity: 1;
}
#owl-login.password .arm-down-left, 
#owl-login.password .arm-down-right {
  transform: scale(0);
  opacity: 0;
}
/* 表单容器 */
.form-container {
  padding: 0 40px 40px;
}
.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
/* 表单项样式 */
.form-item {
  width: 100%;
  margin-bottom: 0 !important;
}
.form-item-button {
  margin-top: 10px;
}
/* Element Plus 表单项重写 */
.form-item :deep(.el-form-item__content) {
  width: 100% !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  margin: 0 !important;
  line-height: normal !important;
}
.form-item :deep(.el-form-item__error) {
  color: #ff6b9d;
  background: rgba(255, 107, 157, 0.1);
  padding: 4px 8px;
  border-radius: 8px;
  margin-top: 8px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 107, 157, 0.2);
  text-align: left;
  font-size: 12px;
  line-height: 1.4;
  position: static !important;
}
/* 输入框样式重写 */
.styled-input {
  width: 100%;
}
.styled-input :deep(.el-input__wrapper) {
  background: rgba(255, 255, 255, 0.1) !important;
  border: 2px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 16px !important;
  box-shadow: none !important;
  transition: all 0.3s ease !important;
  backdrop-filter: blur(10px) !important;
  padding: 0 16px !important;
  height: 56px !important;
  width: 100% !important;
  display: flex !important;
  align-items: center !important;
}
.styled-input :deep(.el-input__wrapper):hover {
  border-color: rgba(255, 255, 255, 0.4) !important;
  background: rgba(255, 255, 255, 0.15) !important;
}
.styled-input :deep(.el-input__wrapper.is-focus) {
  border-color: #6366f1 !important;
  background: rgba(255, 255, 255, 0.2) !important;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1) !important;
}
.styled-input :deep(.el-input__inner) {
  color: rgba(255, 255, 255, 0.9) !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  height: 100% !important;
  line-height: normal !important;
}
.styled-input :deep(.el-input__inner::placeholder) {
  color: rgba(255, 255, 255, 0.5) !important;
}
.styled-input :deep(.el-input__prefix) {
  color: rgba(255, 255, 255, 0.7) !important;
  display: flex !important;
  align-items: center !important;
}
.styled-input :deep(.el-input__suffix) {
  color: rgba(255, 255, 255, 0.7) !important;
  display: flex !important;
  align-items: center !important;
}
.styled-input :deep(.el-input__prefix-inner) {
  color: rgba(255, 255, 255, 0.7) !important;
}
.styled-input :deep(.el-input__suffix-inner) {
  color: rgba(255, 255, 255, 0.7) !important;
}
/* 登录按钮 */
.login-btn {
  width: 100% !important;
  height: 56px !important;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%) !important;
  border: none !important;
  border-radius: 16px !important;
  font-size: 16px !important;
  font-weight: 600 !important;
  color: white !important;
  position: relative !important;
  overflow: hidden !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.login-btn:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.4) !important;
}
.login-btn:active {
  transform: translateY(0) !important;
}
.login-btn.is-disabled {
  background: rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.5) !important;
  box-shadow: none !important;
  transform: none !important;
}
.btn-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  z-index: 2;
}
.btn-icon {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}
.login-btn:hover .btn-icon {
  transform: translateX(4px);
}
/* 波纹效果 */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: ripple-effect 1s ease-out;
  pointer-events: none;
  z-index: 1;
}
@keyframes ripple-effect {
  to {
    transform: scale(4);
    opacity: 0;
  }
}
/* 页脚 */
.login-footer {
  margin-top: 32px;
  text-align: center;
  width: 100%;
}
.feature-tags {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.tag {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}
.tag:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}
/* 响应式设计 */
@media (max-width: 640px) {
  .login-container {
    padding: 15px;
  }
  
  .login-card {
    max-width: 100%;
    border-radius: 20px;
  }
  
  .card-header {
    padding: 30px 30px 15px;
  }
  
  .form-container {
    padding: 0 30px 30px;
  }
  
  .main-title {
    font-size: 24px;
  }
  
  .subtitle {
    font-size: 13px;
  }
  
  .feature-tags {
    gap: 8px;
  }
  
  .floating-circle, .floating-triangle {
    display: none;
  }
}
@media (max-width: 480px) {
  .login-container {
    padding: 10px;
  }
  
  .card-header {
    padding: 25px 20px 15px;
  }
  
  .form-container {
    padding: 0 20px 25px;
  }
  
  .main-title {
    font-size: 22px;
  }
  
  .subtitle {
    font-size: 12px;
  }
  
  .logo-section {
    gap: 15px;
  }
}
@media (max-width: 360px) {
  .main-title {
    font-size: 20px;
  }
}
</style>